<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.Article"%>
<%@page import="java.util.List"%>
<%
User author = (User) request.getAttribute("author");
List<Article> articles = (List<Article>) request.getAttribute("articles"); 
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
Category category = null;

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");

//Set content for seo
String nameServer = UrlHelper.getDomainServer(request);
String title = nameServer + " - " + LanguageHelper.getString("my_article_page");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
</jsp:include>

	<script src="/js/my_articles.js"></script>

            <div id="mainContent" class="left" itemscope itemtype="http://schema.org/ItemList">
                <div id="authorArticlePage">
                	<h3 class="title"><%=LanguageHelper.getString("my_article_page")%></h3>
                    <div class="authorArticle">
						<% 
		                for (int i = 0; i < articles.size(); i++) {
		                	category = categories.get(articles.get(i).getCategory());
		                %>
		                <article class="articleItem">
		                    <h2 class="articleTitle"><a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a></h2>
		                    <div class="articleMeta clearafter">
		                        <%=LanguageHelper.getString("on")%>&nbsp; <%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "MMM dd, yyyy") %> <a href="/c/<%=category.getAlias() %>" class="articleCat right"><%=category.getName() %></a>
		                    </div>                            
		                    <a href="/profile/article/edit/<%=articles.get(i).getId() %>/<%=articles.get(i).getAuthKey() %>" class="edit"><%=LanguageHelper.getString("edit_article")%></a>
		                    <a href="/profile/article/delete/<%=articles.get(i).getId() %>/<%=articles.get(i).getAuthKey() %>" class="delete right"><%=LanguageHelper.getString("delete_article")%></a>
		                </article>
		                <% } %>
                	</div>
	                <ul class="pagination">
	                    <%
						List<Integer> range = paginator.getRangePage();
						%>
	                    <% if (prevPage) { %>
						<li><a href="<%=paginator.getPrev()%>"><%=LanguageHelper.getString("prev")%></a></li>
						<% } %>
						<%
						if (nextPage || prevPage) {
							for (int i = 0; i < range.size(); i++) {
						%>
						<li><a class="<%=range.get(i).intValue() == pages ? "current" : "" %>" href="<%=range.get(i).intValue() == pages ? "javascript: return false;" : paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %> </a></li>
						<%  }
						} %>
						
						<% if (nextPage) { %>
						<li><a href="<%=paginator.getNext()%>"><%=LanguageHelper.getString("next")%></a></li>
						<% } %>
	                </ul>
	            </div>
            </div>
            
            <jsp:include page="/elements/right.jsp" />
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />